package com.fertshop.gui.listener;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.fertshop.dao.FertishopDao;
import com.fertshop.dto.ShopDto;
public class SortSpAreaMIActionListener implements ActionListener{

	private JDesktopPane desktop=null;
	private FertishopDao fertidao=new FertishopDao();
	
	public SortSpAreaMIActionListener(JDesktopPane desktop){
		this.desktop=desktop;
	}
	
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		JInternalFrame viewAllShopsIf=new JInternalFrame("View All Shops");
		Container ctr=viewAllShopsIf.getContentPane();
		ctr.setLayout(new BorderLayout());
		DefaultTableModel tableModel=new DefaultTableModel();
		tableModel.addColumn("Shop Name");
		tableModel.addColumn("Propraitor Name");
		tableModel.addColumn("License Number");
		tableModel.addColumn("Address");
		tableModel.addColumn("Sale Point Door Number");
		tableModel.addColumn("Sale Point Area");
		tableModel.addColumn("Storage Point Door Number");
		tableModel.addColumn("Storage Point Area");		
		
		List<ShopDto> allshops=fertidao.getAllShopsBySalepointArea();
		
		for(int i=0;i<allshops.size();i++){
			ShopDto shop=allshops.get(i);
			Vector<String> rowdata=new Vector<String>();
			rowdata.add(shop.getShopName());
			rowdata.add(shop.getProprietorName());
			rowdata.add(shop.getLicenseNumber());
			rowdata.add(shop.getAddress());
			rowdata.add(shop.getSpDoorNo());
			rowdata.add(shop.getSpArea());
			rowdata.add(shop.getStrgpDoorNo());
			rowdata.add(shop.getStrgpArea());
			tableModel.addRow(rowdata);
		}
		
		JTable table=new JTable(tableModel);
		JScrollPane scroll=new JScrollPane(table);		
		ctr.add(scroll,BorderLayout.CENTER);
		desktop.add(viewAllShopsIf);		
		viewAllShopsIf.setClosable(true);
		viewAllShopsIf.setMaximizable(true);
		viewAllShopsIf.setResizable(true);
		viewAllShopsIf.setIconifiable(true); 
		try { 
			viewAllShopsIf.setSelected(true); 
	 	} catch (java.beans.PropertyVetoException e2) { 
	 	  } 
		viewAllShopsIf.setSize(500, 500);
		viewAllShopsIf.setVisible(true);
		
	}

}
